import QtQuick 1.1
import com.nokia.meego 1.0
import "storage.js" as Store
SelectionDialog {
    id:colorDialog
    property bool showColor: true
    property bool showBackPic: true
    property bool showBookIcon: true
    property bool useName2: false
    property string which
    titleText: "Select color"
    selectedIndex: 0

    function isImageType(type) {
        if (type === 4 || type === 2) {
            return true
        }
        else {
            return false
        }
    }

    function isShowType(type) {
        if ( (type === 1 && showColor) ||
                (type === 2 && showBackPic) ||
                (type === 4 && showBookIcon)) {
            return true
        }
        else {
            return false
        }
    }

    delegate: Rectangle {
        id: colorDelegate
        //Hide when is type and do not show picture
        visible: isShowType(model.type)
        width: parent.width
        height: isShowType(model.type) ? 100 : 0
        color: mouseArea.pressed ? "grey" : "white"
        Label {
            id: colorName
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            verticalAlignment: Text.AlignVCenter
            text: if (colorDialog.useName2) {
                      model.name2
                  }
                  else {
                      model.name
                  }

            width: 150
            height: parent.height
            color: mouseArea.pressed ? "white" : "black"
        }
        Rectangle {
            anchors.verticalCenter: parent.verticalCenter
                       anchors.left: colorName.right
                       anchors.right: parent.right
            width:  parent.width-colorName.width-20
            height: parent.height
            color: isImageType(model.type) ? "transparent" : model.value
            Image {
                anchors.fill: parent
                visible: isImageType(model.type)
               // fillMode: (model.type === 4 && showBookIcon)? Image.PreserveAspectFit : Image.Stretch
                source: isImageType(model.type) ? model.value : ""
                smooth: true
            }
        }
        MouseArea {
            id: mouseArea
            anchors.fill: parent
            onClicked: {
                colorDialog.selectedIndex = index
                console.log("index:="+index)
                var whichcolorla  =  colorModel.get(index).value
                Store.callbackFunction(colorDialog.which,whichcolorla);
                //text1.text  = index;
                colorDialog.accept()
            }
        }
    }

    model: colorModel
    ListModel {
        id: colorModel
        //ListElement { name: "羊皮纸1"; name2: "sheepskin1"; type: 2; value: "images/sheepskinpaper1.jpg"}
        //ListElement { name: "羊皮纸2"; name2: "sheepskin2"; type: 2; value: "images/sheepskinpaper2.jpg"}
        //ListElement { name: "羊皮纸3"; name2: "sheepskin3"; type: 2; value: "images/sheepskinpaper3.jpg"}
        ListElement { name: "浅蓝色"; name2: "aliceblue"; type: 1; value: "aliceblue" }
        ListElement { name: "远古白"; name2: "antiquewhite"; type: 1; value: "antiquewhite" }
        ListElement { name: "浅绿色"; name2: "aqua"; type: 1; value: "aqua" }
        ListElement { name: "蓝绿色"; name2: "aquamarine"; type: 1; value: "aquamarine" }
        ListElement { name: "天蓝色"; name2: "azure"; type: 1; value: "azure" }
        ListElement { name: "米黄色"; name2: "beige"; type: 1; value: "beige" }
        ListElement { name: "素瓷"; name2: "bisque"; type: 1; value: "bisque" }
        ListElement { name: "黑色"; name2: "black"; type: 1; value: "black" }
        ListElement { name: "苍白色"; name2: "blanchedalmond"; type: 1; value: "blanchedalmond" }
        ListElement { name: "蓝色"; name2: "blue"; type: 1; value: "blue" }
        ListElement { name: "蓝紫色"; name2: "blueviolet"; type: 1; value: "blueviolet" }
        ListElement { name: "棕色"; name2: "brown"; type: 1; value: "brown" }
        ListElement { name: "实木色"; name2: "burlywood"; type: 1; value: "burlywood" }
        ListElement { name: "灰蓝色"; name2: "cadetblue"; type: 1; value: "cadetblue" }
        ListElement { name: "黄绿色"; name2: "chartreuse"; type: 1; value: "chartreuse" }
        ListElement { name: "巧克力色"; name2: "chocolate"; type: 1; value: "chocolate" }
        ListElement { name: "珊瑚色"; name2: "coral"; type: 1; value: "coral" }
        ListElement { name: "矢车菊蓝"; name2: "cornflowerblue"; type: 1; value: "cornflowerblue" }
        ListElement { name: "玉米雌穗花丝"; name2: "cornsilk"; type: 1; value: "cornsilk" }
        ListElement { name: "深红色的"; name2: "crimson"; type: 1; value: "crimson" }
        ListElement { name: "蓝绿色"; name2: "cyan"; type: 1; value: "cyan" }
        ListElement { name: "深蓝色"; name2: "darkblue"; type: 1; value: "darkblue" }
        ListElement { name: "深青色"; name2: "darkcyan"; type: 1; value: "darkcyan" }
        ListElement { name: "深秋麒麟色"; name2: "darkgoldenrod"; type: 1; value: "darkgoldenrod" }
        ListElement { name: "深灰色"; name2: "darkgray"; type: 1; value: "darkgray" }
        ListElement { name: "深绿色"; name2: "darkgreen"; type: 1; value: "darkgreen" }
        ListElement { name: "黑灰色"; name2: "darkgrey"; type: 1; value: "darkgrey" }
        ListElement { name: "深卡其色"; name2: "darkkhaki"; type: 1; value: "darkkhaki" }
        ListElement { name: "深紫红色"; name2: "darkmagenta"; type: 1; value: "darkmagenta" }
        ListElement { name: "深橄榄绿"; name2: "darkolivegreen"; type: 1; value: "darkolivegreen" }
        ListElement { name: "暗橙黄"; name2: "darkorange"; type: 1; value: "darkorange" }
        ListElement { name: "暗紫色"; name2: "darkorchid"; type: 1; value: "darkorchid" }
        ListElement { name: "深红色"; name2: "darkred"; type: 1; value: "darkred" }
        ListElement { name: "深肉色"; name2: "darksalmon"; type: 1; value: "darksalmon" }
        ListElement { name: "深海绿色"; name2: "darkseagreen"; type: 1; value: "darkseagreen" }
        ListElement { name: "深石板蓝"; name2: "darkslateblue"; type: 1; value: "darkslateblue" }
        ListElement { name: "深石板灰"; name2: "darkslategray"; type: 1; value: "darkslategray" }
        //        ListElement { name: "darkslategrey"; name2: "darkslategrey"; type: 1; value: "darkslategrey" }
        ListElement { name: "暗宝石绿"; name2: "darkturquoise"; type: 1; value: "darkturquoise" }
        //        ListElement { name: "暗紫色"; name2: "darkviolet"; type: 1; value: "darkviolet" }
        ListElement { name: "深粉红"; name2: "deeppink"; type: 1; value: "deeppink" }
        ListElement { name: "深天蓝"; name2: "deepskyblue"; type: 1; value: "deepskyblue" }
        ListElement { name: "暗灰"; name2: "dimgray"; type: 1; value: "dimgray" }
        //        ListElement { name: "dimgrey"; name2: "dimgrey"; type: 1; value: "dimgrey" }
        ListElement { name: "道奇蓝"; name2: "dodgerblue"; type: 1; value: "dodgerblue" }
        //        ListElement { name: "firebrick"; name2: "firebrick"; type: 1; value: "firebrick" }
        ListElement { name: "花白色"; name2: "floralwhite"; type: 1; value: "floralwhite" }
        ListElement { name: "森林绿"; name2: "forestgreen"; type: 1; value: "forestgreen" }
        ListElement { name: "紫红色"; name2: "fuchsia"; type: 1; value: "fuchsia" }
        //        ListElement { name: "gainsboro"; name2: "gainsboro"; type: 1; value: "gainsboro" }
        ListElement { name: "幽灵白"; name2: "ghostwhite"; type: 1; value: "ghostwhite" }
        ListElement { name: "金色"; name2: "gold"; type: 1; value: "gold" }
        ListElement { name: "黄花"; name2: "goldenrod"; type: 1; value: "goldenrod" }
        ListElement { name: "灰色"; name2: "gray"; type: 1; value: "gray" }
        //        ListElement { name: "grey"; name2: "grey"; type: 1; value: "grey" }
        ListElement { name: "绿色"; name2: "green"; type: 1; value: "green" }
        ListElement { name: "黄绿色"; name2: "greenyellow"; type: 1; value: "greenyellow" }
        //        ListElement { name: "honeydew"; name2: "honeydew"; type: 1; value: "honeydew" }
        ListElement { name: "水红色"; name2: "hotpink"; type: 1; value: "hotpink" }
        ListElement { name: "印度红"; name2: "indianred"; type: 1; value: "indianred" }
        ListElement { name: "靛青"; name2: "indigo"; type: 1; value: "indigo" }
        ListElement { name: "象牙白"; name2: "ivory"; type: 1; value: "ivory" }
        ListElement { name: "土黄色"; name2: "khaki"; type: 1; value: "khaki" }
        ListElement { name: "淡紫色"; name2: "lavender"; type: 1; value: "lavender" }
        ListElement { name: "淡紫红"; name2: "lavenderblush"; type: 1; value: "lavenderblush" }
        ListElement { name: "草绿色"; name2: "lawngreen"; type: 1; value: "lawngreen" }
        //        ListElement { name: "lemonchiffon"; name2: "lemonchiffon"; type: 1; value: "lemonchiffon" }
        ListElement { name: "淡蓝色"; name2: "lightblue"; type: 1; value: "lightblue" }
        ListElement { name: "淡珊瑚色"; name2: "lightcoral"; type: 1; value: "lightcoral" }
        ListElement { name: "浅蓝色"; name2: "lightcyan"; type: 1; value: "lightcyan" }
        //        ListElement { name: "lightgoldenrodyellow"; name2: "lightgoldenrodyellow"; type: 1; value: "lightgoldenrodyellow" }
        //        ListElement { name: "lightgray"; name2: "lightgray"; type: 1; value: "lightgray" }
        ListElement { name: "浅绿色"; name2: "lightgreen"; type: 1; value: "lightgreen" }
        ListElement { name: "浅灰色"; name2: "lightgrey"; type: 1; value: "lightgrey" }
        ListElement { name: "浅粉色"; name2: "lightpink"; type: 1; value: "lightpink" }
        ListElement { name: "浅肉色"; name2: "lightsalmon"; type: 1; value: "lightsalmon" }
        ListElement { name: "淡海绿色"; name2: "lightseagreen"; type: 1; value: "lightseagreen" }
        ListElement { name: "淡天蓝色"; name2: "lightskyblue"; type: 1; value: "lightskyblue" }
        //        ListElement { name: "lightslategray"; name2: "lightslategray"; type: 1; value: "lightslategray" }
        //        ListElement { name: "lightslategrey"; name2: "lightslategrey"; type: 1; value: "lightslategrey" }
        ListElement { name: "淡钢蓝"; name2: "lightsteelblue"; type: 1; value: "lightsteelblue" }
        ListElement { name: "淡黄"; name2: "lightyellow"; type: 1; value: "lightyellow" }
        //        ListElement { name: "lime"; name2: "lime"; type: 1; value: "lime" }
        ListElement { name: "淡黄绿色"; name2: "limegreen"; type: 1; value: "limegreen" }
        //        ListElement { name: "linen"; name2: "linen"; type: 1; value: "linen" }
        ListElement { name: "紫红色"; name2: "magenta"; type: 1; value: "magenta" }
        ListElement { name: "褐红色的"; name2: "maroon"; type: 1; value: "maroon" }
        //        ListElement { name: "mediumaquamarine"; name2: "mediumaquamarine"; type: 1; value: "mediumaquamarine" }
        //        ListElement { name: "mediumblue"; name2: "mediumblue"; type: 1; value: "mediumblue" }
        ListElement { name: "中兰花紫"; name2: "mediumorchid"; type: 1; value: "mediumorchid" }
        ListElement { name: "中紫色"; name2: "mediumpurple"; type: 1; value: "mediumpurple" }
        ListElement { name: "中海洋绿"; name2: "mediumseagreen"; type: 1; value: "mediumseagreen" }
        ListElement { name: "中板岩暗蓝灰色"; name2: "mediumslateblue"; type: 1; value: "mediumslateblue" }
        ListElement { name: "中春绿色"; name2: "mediumspringgreen"; type: 1; value: "mediumspringgreen" }
        ListElement { name: "中宝石绿"; name2: "mediumturquoise"; type: 1; value: "mediumturquoise" }
        ListElement { name: "中紫罗兰色"; name2: "mediumvioletred"; type: 1; value: "mediumvioletred" }
        ListElement { name: "深蓝"; name2: "midnightblue"; type: 1; value: "midnightblue" }
        ListElement { name: "薄荷乳色"; name2: "mintcream"; type: 1; value: "mintcream" }
        ListElement { name: "淡玫瑰色"; name2: "mistyrose"; type: 1; value: "mistyrose" }
        //        ListElement { name: "moccasin"; name2: "moccasin"; type: 1; value: "moccasin" }
        //        ListElement { name: "navajowhite"; name2: "navajowhite"; type: 1; value: "navajowhite" }
        ListElement { name: "海军蓝"; name2: "navy"; type: 1; value: "navy" }
        ListElement { name: "浅米色"; name2: "oldlace"; type: 1; value: "oldlace" }
        ListElement { name: "橄榄色"; name2: "olive"; type: 1; value: "olive" }
        ListElement { name: "草绿色"; name2: "olivedrab"; type: 1; value: "olivedrab" }
        ListElement { name: "橙色"; name2: "orange"; type: 1; value: "orange" }
        ListElement { name: "橙红色"; name2: "orangered"; type: 1; value: "orangered" }
        ListElement { name: "淡紫色"; name2: "orchid"; type: 1; value: "orchid" }
        ListElement { name: "淡麒麟色"; name2: "palegoldenrod"; type: 1; value: "palegoldenrod" }
        ListElement { name: "浅绿"; name2: "palegreen"; type: 1; value: "palegreen" }
        //        ListElement { name: "paleturquoise"; name2: "paleturquoise"; type: 1; value: "paleturquoise" }
        ListElement { name: "白紫罗兰"; name2: "palevioletred"; type: 1; value: "palevioletred" }
        ListElement { name: "番木色"; name2: "papayawhip"; type: 1; value: "papayawhip" }
        ListElement { name: "桃色"; name2: "peachpuff"; type: 1; value: "peachpuff" }
        //        ListElement { name: "peru"; name2: "peru"; type: 1; value: "peru" }
        ListElement { name: "粉红色"; name2: "pink"; type: 1; value: "pink" }
        ListElement { name: "紫红色"; name2: "plum"; type: 1; value: "plum" }
        ListElement { name: "浅灰蓝色"; name2: "powderblue"; type: 1; value: "powderblue" }
        ListElement { name: "紫色"; name2: "purple"; type: 1; value: "purple" }
        ListElement { name: "红色"; name2: "red"; type: 1; value: "red" }
        ListElement { name: "褐玫瑰红"; name2: "rosybrown"; type: 1; value: "rosybrown" }
        ListElement { name: "品蓝"; name2: "royalblue"; type: 1; value: "royalblue" }
        //        ListElement { name: "saddlebrown"; name2: "saddlebrown"; type: 1; value: "saddlebrown" }
        ListElement { name: "橙红色"; name2: "salmon"; type: 1; value: "salmon" }
        ListElement { name: "沙褐色"; name2: "sandybrown"; type: 1; value: "sandybrown" }
        ListElement { name: "海绿色"; name2: "seagreen"; type: 1; value: "seagreen" }
        ListElement { name: "贝壳色"; name2: "seashell"; type: 1; value: "seashell" }
        ListElement { name: "黄褐色"; name2: "sienna"; type: 1; value: "sienna" }
        ListElement { name: "银色"; name2: "silver"; type: 1; value: "silver" }
        ListElement { name: "天蓝色"; name2: "skyblue"; type: 1; value: "skyblue" }
        ListElement { name: "石板蓝"; name2: "slateblue"; type: 1; value: "slateblue" }
        //        ListElement { name: "slategray"; name2: "slategray"; type: 1; value: "slategray" }
        ListElement { name: "瓦灰色"; name2: "slategrey"; type: 1; value: "slategrey" }
        ListElement { name: "雪白"; name2: "snow"; type: 1; value: "snow" }
        ListElement { name: "春绿"; name2: "springgreen"; type: 1; value: "springgreen" }
        ListElement { name: "钢青色"; name2: "steelblue"; type: 1; value: "steelblue" }
        ListElement { name: "棕褐色"; name2: "tan"; type: 1; value: "tan" }
        ListElement { name: "蓝绿色"; name2: "teal"; type: 1; value: "teal" }
        //        ListElement { name: "thistle"; name2: "thistle"; type: 1; value: "thistle" }
        ListElement { name: "番茄红"; name2: "tomato"; type: 1; value: "tomato" }
        ListElement { name: "青绿色"; name2: "turquoise"; type: 1; value: "turquoise" }
        ListElement { name: "紫罗兰"; name2: "violet"; type: 1; value: "violet" }
        ListElement { name: "小麦色"; name2: "wheat"; type: 1; value: "wheat" }
        ListElement { name: "白色"; name2: "white"; type: 1; value: "white" }
        ListElement { name: "白烟色"; name2: "whitesmoke"; type: 1; value: "whitesmoke" }
        ListElement { name: "黄色"; name2: "yellow"; type: 1; value: "yellow" }
        ListElement { name: "黄绿色"; name2: "yellowgreen"; type: 1; value: "yellowgreen" }
    }

}
